/** 
 * @Description: 
 * @Author: 胡涛
 * @Date: 2024-01-13 21:08:25
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-05-24 23:30:05
 */
/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2024-01-13 21:08:25
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-07-17 23:23:41
 */
import axios from "axios";

/**
 * 请求对象
 */
export type AuthRequestDto = {
  username: string;
  password: string;
  client_id?: string;
  grant_type?: string;
  scope?: string;
};

/**
 * 登录授权token
 */
export type AuthTokenResponseDto = {
  access_token: string;
  token_type: string;
  expires_in: number;
  refresh_token?: string;
};

export default {
  /**
   * 用户登录
   * @param data
   * @returns
   */
  loginUser(data: AuthRequestDto): Promise<AuthTokenResponseDto> {
    return axios
      .post(
        "/connect/token",
        {
          client_id: "PlatfromApp",
          grant_type: "password",
          scope: "EcoSystem",
          account_type: "admin",
          ...data,
        },
        {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
        }
      )
      .then((res) => {
        return res.data;
      });
  },
};
